import request from "@/utils/axios";
import { QueryParams, NoticeData, NoticeResponse } from "./types"
import type { AxiosResponse } from "axios";

/**
 * 用于调用 API 接口的函数
 * @method NoticeApi 获取通知相关
 */

export default {
    // 获取通知列表
    getNotices(params?: QueryParams): Promise<AxiosResponse<NoticeResponse>> {
      return request({
        url: '/api/notice',
        method: 'get',
        params
      })
    },
  
    // 获取单个通知详情
    getNotice(noticeId: string | number): Promise<AxiosResponse<NoticeData>> {
      return request({
        url: `/api/notice/${noticeId}`,
        method: 'get'
      })
    },
  
    // 创建通知
    createNotice(data: NoticeData): Promise<AxiosResponse<NoticeData>> {
      return request({
        url: '/api/notice',
        method: 'post',
        data
      })
    },
  
    // 批量创建通知
    createNotices(noticeList: NoticeData[]): Promise<AxiosResponse<NoticeData>> {
      return request({
        url: '/api/notice',
        method: 'post',
        data: {
          NoticeList: JSON.stringify(noticeList)
        }
      })
    },
  
    // 更新通知
    updateNotice(noticeId: string | number, data: NoticeData): Promise<AxiosResponse<NoticeData>> {
      return request({
        url: `/api/notice/${noticeId}`,
        method: 'put',
        data
      })
    },
  
    // 删除通知
    deleteNotice(noticeId: string | number): Promise<AxiosResponse<NoticeData>> {
      return request({
        url: `/api/notice/${noticeId}`,
        method: 'delete'
      })
    }
  }